package images;

import game.TextManager;
import org.newdawn.slick.opengl.Texture;
import saves.items.Equipamento;

/**
 *
 * @author Luan
 */
public class ItemLoader {
    
    private static Texture imgIcons;
    private static ImageInfo[] items, upgrades;
    
    public static void load() {
        imgIcons = ImageManager.getTexture("icons.png");
        float px = imgIcons.getWidth()/imgIcons.getImageWidth(),
              py = imgIcons.getHeight()/imgIcons.getImageHeight();

        items = new ImageInfo[1];
        items[0] = new ImageInfo(0, 0, 32, 32, 0, px, py);
        
        upgrades = new ImageInfo[TextManager.t().UPGRADES_NAMES.length];
        for (int i = 0; i < upgrades.length; i++)
            upgrades[i] = new ImageInfo(i*32, 32, 32, 32, 0, px, py);
    }
    
    public static void bindTexture() {
        imgIcons.bind();
    }
    
    public static void drawItem(int code, int x, int y, int s) {
        if (code != -1) {
            bindTexture();
            items[code].draw(x, y, s, s);
        }
    }
    
    public static void drawUpgrade(int code, int x, int y, int s) {
        if (code != -1) {
            bindTexture();
            upgrades[code].draw(x, y, s, s);
        }
    }
    
    public static void drawEquip(Equipamento e, int x, int y, int s) {
        drawEquip(e, x, y, s, 0);
    }
    
    public static void drawEquip(Equipamento e, int x, int y, int s, int r) {
        float k = (float) s/ShipLoader.DEFAULT_SHIP_SIZE;
        ShipLoader.draw(e, x, y, (int) ((s - k*ShipLoader.getWidth(e.getCodModelo()))/(k*2)), (int) ((s - k*ShipLoader.getHeight(e.getCodModelo()))/(k*2)), k, r);
    }
}